<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>git学习 | Abel&#39;Blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="安装 Linux   工作流程 概念： 工作区操作 远程操作 分支管理 分支合并     git 修改远程的目录 git转换换行符（回车） tags冲突 参考  学习git的笔记，将记录一下git如何使用。之前常用svn，现在转过来的时候，有些东西需要熟悉。将会持续更新此文档。 安装LinuxUbuntu 1234567$ apt-get install libcurl4-gnutls-dev">
<meta property="og:type" content="article">
<meta property="og:title" content="git学习">
<meta property="og:url" content="http://example.com/2020/11/04/2020/2020-11-04-learn_git/index.html">
<meta property="og:site_name" content="Abel&#39;Blog">
<meta property="og:description" content="安装 Linux   工作流程 概念： 工作区操作 远程操作 分支管理 分支合并     git 修改远程的目录 git转换换行符（回车） tags冲突 参考  学习git的笔记，将记录一下git如何使用。之前常用svn，现在转过来的时候，有些东西需要熟悉。将会持续更新此文档。 安装LinuxUbuntu 1234567$ apt-get install libcurl4-gnutls-dev">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://s1.ax1x.com/2020/11/11/Bj6XOe.jpg">
<meta property="article:published_time" content="2020-11-03T16:00:00.000Z">
<meta property="article:modified_time" content="2021-07-28T08:13:02.100Z">
<meta property="article:author" content="Abel Sean">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2020/11/11/Bj6XOe.jpg">
  
    <link rel="alternate" href="/atom.xml" title="Abel&#39;Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Abel&#39;Blog</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-2020/2020-11-04-learn_git" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/11/04/2020/2020-11-04-learn_git/" class="article-date">
  <time datetime="2020-11-03T16:00:00.000Z" itemprop="datePublished">2020-11-04</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      git学习
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <ul>
<li><a href="#%E5%AE%89%E8%A3%85">安装</a><ul>
<li><a href="#linux">Linux</a></li>
</ul>
</li>
<li><a href="#%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B">工作流程</a><ul>
<li><a href="#%E6%A6%82%E5%BF%B5">概念：</a></li>
<li><a href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA%E6%93%8D%E4%BD%9C">工作区操作</a></li>
<li><a href="#%E8%BF%9C%E7%A8%8B%E6%93%8D%E4%BD%9C">远程操作</a><ul>
<li><a href="#%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86">分支管理</a></li>
<li><a href="#%E5%88%86%E6%94%AF%E5%90%88%E5%B9%B6">分支合并</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#git-%E4%BF%AE%E6%94%B9%E8%BF%9C%E7%A8%8B%E7%9A%84%E7%9B%AE%E5%BD%95">git 修改远程的目录</a></li>
<li><a href="#git%E8%BD%AC%E6%8D%A2%E6%8D%A2%E8%A1%8C%E7%AC%A6%E5%9B%9E%E8%BD%A6">git转换换行符（回车）</a></li>
<li><a href="#tags%E5%86%B2%E7%AA%81">tags冲突</a></li>
<li><a href="#%E5%8F%82%E8%80%83">参考</a></li>
</ul>
<p>学习git的笔记，将记录一下git如何使用。之前常用svn，现在转过来的时候，有些东西需要熟悉。将会持续更新此文档。</p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><h3 id="Linux"><a href="#Linux" class="headerlink" title="Linux"></a>Linux</h3><p>Ubuntu</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \</span><br><span class="line">  libz-dev libssl-dev</span><br><span class="line"></span><br><span class="line">$ apt-get install git</span><br><span class="line"></span><br><span class="line">$ git --version</span><br><span class="line">git version 1.8.1.2</span><br></pre></td></tr></table></figure>

<p>Centos/RedHat</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ yum install curl-devel expat-devel gettext-devel \</span><br><span class="line">  openssl-devel zlib-devel</span><br><span class="line"></span><br><span class="line">$ yum -y install git-core</span><br><span class="line"></span><br><span class="line">$ git --version</span><br><span class="line">git version 1.7.1</span><br></pre></td></tr></table></figure>

<p>设置自己的用户名</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git config --global user.name <span class="string">&quot;Your Name&quot;</span></span><br><span class="line">$ git config --global user.email <span class="string">&quot;email@example.com&quot;</span></span><br></pre></td></tr></table></figure>

<p>Linux中记住密码的方式：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在Linux里面记住密码的文件，这个文件需要创建在本工程目录之下，而不是在系统根目录下。</span></span><br><span class="line"><span class="comment"># http(s)://&#123;你的用户名&#125;:&#123;你的密码&#125;@你的服务器地址</span></span><br><span class="line"><span class="comment"># git config --global credential.helper store</span></span><br><span class="line">.git-credentials</span><br><span class="line"></span><br><span class="line"><span class="comment"># mac机器上保存密码</span></span><br><span class="line">git config --global credential.helper osxkeychain</span><br></pre></td></tr></table></figure>

<h2 id="工作流程"><a href="#工作流程" class="headerlink" title="工作流程"></a>工作流程</h2><h3 id="概念："><a href="#概念：" class="headerlink" title="概念："></a>概念：</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="left">远程 Git 资源</td>
<td align="left">共享git版本的一个库</td>
</tr>
<tr>
<td align="left">工作区</td>
<td align="left">本地编辑</td>
</tr>
<tr>
<td align="left">暂存区</td>
<td align="left">本地修改了之后，可以将修改提交到本地</td>
</tr>
<tr>
<td align="left">推送</td>
<td align="left">将本地的内容推送到远程Git资源服</td>
</tr>
</tbody></table>
<p><a target="_blank" rel="noopener" href="https://imgchr.com/i/Bj6XOe"><img src="https://s1.ax1x.com/2020/11/11/Bj6XOe.jpg" alt="Bj6XOe.jpg"></a></p>
<h3 id="工作区操作"><a href="#工作区操作" class="headerlink" title="工作区操作"></a>工作区操作</h3><blockquote>
<p>查询状态</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git status</span><br></pre></td></tr></table></figure>

<h3 id="远程操作"><a href="#远程操作" class="headerlink" title="远程操作"></a>远程操作</h3><h4 id="分支管理"><a href="#分支管理" class="headerlink" title="分支管理"></a>分支管理</h4><blockquote>
<p>列出分支</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">abel@xiaozanbiao:~/xxxx$ git branch -a</span><br><span class="line">* master</span><br><span class="line">  remotes/origin/HEAD -&gt; origin/master</span><br><span class="line">  remotes/origin/abel_learn</span><br><span class="line">  remotes/origin/develop_xcs</span><br><span class="line">  remotes/origin/master</span><br></pre></td></tr></table></figure>

<p>这个里面将会显示远程分支和本地分支；</p>
<blockquote>
<p>将远程的分支切换到本地分支</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b &lt;本地名称&gt; &lt;远程地址&gt;</span><br><span class="line">git checkout -b abel_learn origin/develop_xcs</span><br></pre></td></tr></table></figure>

<p>在操作的时候，需要将远程的分支，在本地做一次checkout</p>
<p>在本地切换分支，切换将直接使用checkout</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@test-qingzhou-01 new_project_server]<span class="comment"># git checkout master</span></span><br><span class="line">Switched to branch <span class="string">&#x27;master&#x27;</span></span><br><span class="line">Your branch is behind <span class="string">&#x27;origin/master&#x27;</span> by 225 commits, and can be fast-forwarded.</span><br><span class="line">  (use <span class="string">&quot;git pull&quot;</span> to update your <span class="built_in">local</span> branch)</span><br><span class="line">[root@test-qingzhou-01 new_project_server]<span class="comment"># git branch</span></span><br><span class="line">  develop_xcs</span><br><span class="line">* master</span><br><span class="line">[root@test-qingzhou-01 new_project_server]<span class="comment"># git branch develop_xcs</span></span><br><span class="line">fatal: A branch named <span class="string">&#x27;develop_xcs&#x27;</span> already exists.</span><br></pre></td></tr></table></figure>

<blockquote>
<p>删除分支</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -d [branchname]</span><br></pre></td></tr></table></figure>

<blockquote>
<p>合并分支</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git merge [otherbranch]</span><br></pre></td></tr></table></figure>

<blockquote>
<p>转移文件</p>
</blockquote>
<p>这个指令的好处是不会影响文件历史日志，如果直接删除并且增加那就比较麻烦了。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git mv <span class="built_in">source</span> dst</span><br></pre></td></tr></table></figure>

<h4 id="分支合并"><a href="#分支合并" class="headerlink" title="分支合并"></a>分支合并</h4><p>之前工作中使用svn来做分支管理。如果在trunk里面修改的bug需要合并到release分支的时候，需要使用merge来操作。</p>
<p>在git里面也有如此的概念，使用的是遴选（cherry pick）。在vscode里面使用git插件就能做这个操作了。有空可以研究一下具体如何通过命令行来出来这个事情。</p>
<p>使用命令行来使用；</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> D:\work\trunk\xxxx&gt; git cherry<span class="literal">-pick</span> <span class="number">7</span>e1e57d</span><br><span class="line">[<span class="type">VerDemo</span> <span class="type">e610a68</span>] 【需求】 <span class="comment">#1367 服务器增加日志，检查登录无法加载角色的问题 防止出现“保留房间超时被释放”</span></span><br><span class="line"> Date: Tue Mar <span class="number">23</span> <span class="number">20</span>:<span class="number">01</span>:<span class="number">32</span> <span class="number">2021</span> +<span class="number">0800</span></span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+), <span class="number">1</span> deletion(-)</span><br><span class="line"><span class="built_in">PS</span> D:\work\trunk\xxxx&gt; git push</span><br><span class="line">Enumerating objects: <span class="number">11</span>, done.</span><br><span class="line">Counting objects: <span class="number">100</span>% (<span class="number">11</span>/<span class="number">11</span>), done.</span><br><span class="line">Delta compression <span class="keyword">using</span> up to 8 threads</span><br><span class="line">Compressing objects: <span class="number">100</span>% (<span class="number">6</span>/<span class="number">6</span>), done.</span><br><span class="line">Writing objects: <span class="number">100</span>% (<span class="number">6</span>/<span class="number">6</span>), <span class="number">619</span> bytes | <span class="number">619.00</span> KiB/s, done.</span><br><span class="line">Total <span class="number">6</span> (delta <span class="number">5</span>), reused <span class="number">0</span> (delta <span class="number">0</span>), pack<span class="literal">-reused</span> <span class="number">0</span></span><br><span class="line">remote: Powered by GITEE.COM [<span class="type">GNK</span>-<span class="number">5.0</span>]</span><br><span class="line">To https://gitee.com/xxxx/xxx.git</span><br><span class="line">   f9819ca..e610a68  VerDemo -&gt; VerDemo</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="http://www.ruanyifeng.com/blog/2020/04/git-cherry-pick.html">git cherry-pick 教程</a></p>
<p>git rebase 和 git cherry pick 有些类似。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fatal: You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).</span><br><span class="line">Please, commit your changes before you merge.</span><br><span class="line"><span class="comment"># 使用命令放弃 git cherry-pick 变更</span></span><br><span class="line">git cherry-pick --abort </span><br></pre></td></tr></table></figure>

<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">would clobber existing tag</span><br></pre></td></tr></table></figure>

<p>本地的tag和远程的tag冲突。</p>
<p>I’m using git in VSCodium and each time I try to pull git is complaining.</p>
<p>Looking into the log I see</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&gt; git pull --tags origin master</span><br><span class="line">From https://github.com/MY/REPO</span><br><span class="line"> * branch            master     -&gt; FETCH_HEAD</span><br><span class="line"> ! [rejected]        latest     -&gt; latest  (would clobber existing tag)</span><br><span class="line">   9428765..935da94  master     -&gt; origin/master</span><br><span class="line"></span><br><span class="line">git fetch --tags -f</span><br></pre></td></tr></table></figure>

<h2 id="git-修改远程的目录"><a href="#git-修改远程的目录" class="headerlink" title="git 修改远程的目录"></a>git 修改远程的目录</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看全部远程地址</span></span><br><span class="line">git remote -v</span><br><span class="line"><span class="comment"># 保存远程地址</span></span><br><span class="line">git remote set-url --add origin http://safjdklasjkflda</span><br><span class="line">git push -u other_origin master</span><br><span class="line">git pull -u other_origin master</span><br></pre></td></tr></table></figure>

<h2 id="git转换换行符（回车）"><a href="#git转换换行符（回车）" class="headerlink" title="git转换换行符（回车）"></a>git转换换行符（回车）</h2><p>git配置一共分为3个级别，可以通过这个命令来查看。</p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git config --system --list</span><br><span class="line">git config --global --list</span><br><span class="line">git config --local --list</span><br></pre></td></tr></table></figure>

<p>这个概念类似于环境变量。</p>
<p>其中 core.autocrlf 是决定了文件的回车方式。</p>
<p>true：提交的时候自动将CRLF转换成LF，签出时自动将LF转换成CRLF；<br>input：提交的时候CRLF转换成LF，签出时不转换；<br>false：将回车记录到库中</p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global core.autocrlf [true|input|false]</span><br></pre></td></tr></table></figure>

<p>pull 根据不同的配置，可等于 fetch + merge 或 fetch + rebase。具体了解可继续读下去。</p>
<h2 id="tags冲突"><a href="#tags冲突" class="headerlink" title="tags冲突"></a>tags冲突</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看远程tags</span></span><br><span class="line">git ls-remote -t</span><br><span class="line"><span class="comment"># 查看本地tags</span></span><br><span class="line">git tag -l</span><br><span class="line"><span class="comment"># 删除本地与远程不一致的tag</span></span><br><span class="line">git tag -d tag名字</span><br><span class="line"><span class="comment"># 重新拉取远程tag</span></span><br><span class="line">git fetch origin --prune-tags</span><br></pre></td></tr></table></figure>

<p>实例：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">PS</span> D:\work\trunk\new_project_server&gt; git <span class="built_in">ls</span><span class="literal">-remote</span> <span class="literal">-t</span>  </span><br><span class="line">From http://xxxxxxxxxxxxxxx.git</span><br><span class="line"><span class="number">0285</span>d7e51bb70b59f132831d8593bb09f1b2ae90        refs/tags/CETag</span><br><span class="line"><span class="number">22</span>bb6f654eab74d570007e2644b6874fc0e2d4fd        refs/tags/demoTag</span><br><span class="line"><span class="number">5428836</span>d1c8f9996987179630cba7f86e00f07df        refs/tags/demoTag^&#123;&#125;</span><br><span class="line"><span class="number">48880</span>c2a1b10d71c47c4b1e1fa95ebdf88217924        refs/tags/v0.<span class="number">0.1</span></span><br><span class="line"><span class="number">5428836</span>d1c8f9996987179630cba7f86e00f07df        refs/tags/v0.<span class="number">0.1</span>^&#123;&#125;</span><br><span class="line"><span class="number">7</span>de8e2d0af4841ec688ba2a1a35dcc84a91bbb9e        refs/tags/verCE</span><br><span class="line"><span class="built_in">PS</span> D:\work\trunk\new_project_server&gt; git tag <span class="literal">-l</span> </span><br><span class="line">CETag</span><br><span class="line">demoTag</span><br><span class="line">v0.<span class="number">0.1</span></span><br><span class="line">verCE</span><br><span class="line"><span class="built_in">PS</span> D:\work\trunk\new_project_server&gt; git tag <span class="literal">-d</span> CETag</span><br><span class="line">Deleted tag <span class="string">&#x27;CETag&#x27;</span> (was <span class="number">805</span>af40b)</span><br><span class="line"><span class="built_in">PS</span> D:\work\trunk\new_project_server&gt; git pull -<span class="literal">-tags</span> origin develop</span><br><span class="line">From http://xxxxxxxxxxxxxxx</span><br><span class="line"> * branch              develop    -&gt; FETCH_HEAD</span><br><span class="line"> * [<span class="type">new</span> <span class="type">tag</span>]           CETag      -&gt; CETag</span><br><span class="line">Already up to date.</span><br></pre></td></tr></table></figure>

<p>服务器报错</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">PS D:\work\trun&gt; git fetch --tags -f</span><br><span class="line">warning: ----------------- SECURITY WARNING ----------------</span><br><span class="line">warning: | TLS certificate verification has been disabled! |</span><br><span class="line">warning: ---------------------------------------------------</span><br><span class="line">warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify <span class="keyword">for</span> more information.</span><br><span class="line">warning: ----------------- SECURITY WARNING ----------------</span><br><span class="line">warning: | TLS certificate verification has been disabled! |</span><br><span class="line">warning: ---------------------------------------------------</span><br><span class="line">warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify <span class="keyword">for</span> more information.</span><br></pre></td></tr></table></figure>

<p>git撤销掉本地的commit</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset HEAD~</span><br></pre></td></tr></table></figure>

<p>有时候git的提交我们需要回滚已经在本地提交的东西。可以通过执行。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Reset current branch to this commit</span><br><span class="line">git push -f origin/develop</span><br></pre></td></tr></table></figure>

<p>reset 模式</p>
<p>git reset –-soft：回退到某个版本，只回退了commit的信息，不会恢复到index file一级。如果还要提交，直接commit即可<br>git reset -–hard：彻底回退到某个版本，本地的源码也会变为上一个版本的内容，撤销的commit中所包含的更改被冲掉</p>
<p>删除分支</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ git branch -d develop_pos</span><br><span class="line">Deleted branch develop_pos (was 83fa957c).</span><br><span class="line">$ git push origin --delete develop_pos</span><br><span class="line">remote: . Processing 1 references</span><br><span class="line">remote: Processed 1 references <span class="keyword">in</span> total</span><br><span class="line">http://xxxxx.git</span><br><span class="line"> - [deleted]           develop_pos</span><br></pre></td></tr></table></figure>

<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
<li>[1] <a target="_blank" rel="noopener" href="https://www.runoob.com/git/git-tutorial.html">Git菜鸟教程</a></li>
<li>[2] <a target="_blank" rel="noopener" href="https://www.liaoxuefeng.com/wiki/896043488029600">廖雪峰-Git教程</a></li>
<li>[3] <a target="_blank" rel="noopener" href="https://git-scm.com/book/zh/v2">官网手册</a></li>
<li>[4] <a target="_blank" rel="noopener" href="https://stackoverflow.com/questions/58031165/how-to-get-rid-of-would-clobber-existing-tag">clobber-existing-tag</a></li>
<li>[5] <a target="_blank" rel="noopener" href="https://www.zhihu.com/question/38305012">git pull 和 git fetch的区别？</a></li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2020/11/04/2020/2020-11-04-learn_git/" data-id="ckrn3an6z000h20xw7v0500z0" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/git/" rel="tag">git</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/11/10/2020/2020-11-10-linux-env-init/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Linux-环境配置
        
      </div>
    </a>
  
  
    <a href="/2020/11/04/2020/2020-11-04-redis-%E4%B9%90%E8%A7%82%E9%94%81/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">redis-乐观锁</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/3D/" rel="tag">3D</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AI/" rel="tag">AI</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Game/" rel="tag">Game</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Go/" rel="tag">Go</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Math/" rel="tag">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Server/" rel="tag">Server</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Unreal-Engine4/" rel="tag">Unreal Engine4</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/golang/" rel="tag">golang</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/guitar/" rel="tag">guitar</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/node-js/" rel="tag">node.js</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/" rel="tag">protobuf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/recast/" rel="tag">recast</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/type/" rel="tag">type</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vscode/" rel="tag">vscode</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BF%90%E7%BB%B4/" rel="tag">运维</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/3D/" style="font-size: 10px;">3D</a> <a href="/tags/AI/" style="font-size: 11.67px;">AI</a> <a href="/tags/C/" style="font-size: 15px;">C++</a> <a href="/tags/Game/" style="font-size: 18.33px;">Game</a> <a href="/tags/Go/" style="font-size: 13.33px;">Go</a> <a href="/tags/Linux/" style="font-size: 13.33px;">Linux</a> <a href="/tags/Math/" style="font-size: 11.67px;">Math</a> <a href="/tags/Server/" style="font-size: 16.67px;">Server</a> <a href="/tags/Unreal-Engine4/" style="font-size: 10px;">Unreal Engine4</a> <a href="/tags/git/" style="font-size: 10px;">git</a> <a href="/tags/golang/" style="font-size: 20px;">golang</a> <a href="/tags/guitar/" style="font-size: 10px;">guitar</a> <a href="/tags/node-js/" style="font-size: 10px;">node.js</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/recast/" style="font-size: 11.67px;">recast</a> <a href="/tags/redis/" style="font-size: 10px;">redis</a> <a href="/tags/type/" style="font-size: 10px;">type</a> <a href="/tags/vscode/" style="font-size: 10px;">vscode</a> <a href="/tags/%E8%BF%90%E7%BB%B4/" style="font-size: 16.67px;">运维</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">June 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/04/">April 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/03/">March 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">January 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/12/">December 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/11/">November 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/11/">November 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/07/19/2021/2021-07-19-etcd-learn/">go-etcd阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/07/19/2021/2021-07-19-socketop-learn/">REUSEPORT-REUSEADDR-学习</a>
          </li>
        
          <li>
            <a href="/2021/06/22/2021/2021-06-22-go-ethereum-learn/">go-ethereum阅读笔记</a>
          </li>
        
          <li>
            <a href="/2021/06/21/2021/2021-06-21-server%E6%B5%8B%E8%AF%95%E5%B7%A5%E5%85%B7/">server测试工具</a>
          </li>
        
          <li>
            <a href="/2021/06/09/2021/2021-06-09-pprof-doc/">go-pprof</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Abel Sean<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>